#coding:utf-8
# 求逆矩阵

from Matrix import Matrix

from _det import _det
from _adj import _adj
from _mul import _mul

def _inv(this):
    if this.row != this.col:
        raise ValueError('只有方阵可以求逆!')
    return _mul( _adj(this) , 1.0/_det(this) )
    

# 测试语句
def test():
    mt = Matrix(
        [-3,2,-5],
        [-1,0,-2],
        [3,-4,1])
    
    print('矩阵的逆和矩阵相乘')
    print( _mul(_inv(mt),mt))
    print('得到对角矩阵')
    
if __name__=='__main__':
    import sys
    test()